<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="130px">
      <el-form-item label="转存任务编号" prop="transferNo">
        <el-input
            v-model="queryParams.transferNo"
            placeholder="请输入转存任务编号"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="转入供电单位编号" prop="transferOrgNo">
        <el-input
            v-model="queryParams.transferOrgNo"
            placeholder="请输入转入供电单位编号"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="转入档案室编号" prop="transferInRoomNo">
        <el-input
            v-model="queryParams.transferInRoomNo"
            placeholder="请输入转入档案室编号"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="转出档案室编号" prop="transferOutRoomNo">
        <el-input
            v-model="queryParams.transferOutRoomNo"
            placeholder="请输入转出档案室编号"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            icon="Document"
            @click="DAVisible"
            v-hasPermi="['archive:ArchiveUploadTaskArchive:export']"
        >档案</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            icon="Notebook"
            @click="BoxVisible"
            v-hasPermi="['archive:ArchiveUploadTaskArchive:export']"
        >档案盒</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            icon="Goods"
            @click="BagVisible"
            v-hasPermi="['archive:ArchiveUploadTaskArchive:export']"
        >档案袋</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="Download"
          @click="handleExport"
          v-hasPermi="['archive:ArchiveUploadTaskArchive:export']"
          v-show="DAShow"
        >导出档案</el-button>
        <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExportBox"
            v-hasPermi="['archive:ArchiveUploadTaskArchive:export']"
            v-show="BoxShow"
        >导出档案盒</el-button>
        <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExportBag"
            v-hasPermi="['archive:ArchiveUploadTaskArchive:export']"
            v-show="BagShow"
        >导出档案袋</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :data="ArchiveUploadTaskArchiveList" @selection-change="handleSelectionChange" v-show="DAShow" >
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="转存任务编号" align="center" prop="transferNo" width="120"/>
      <el-table-column label="申请供电单位编号" align="center" prop="orgNo" width="150" />
      <el-table-column label="转入供电单位编号" align="center" prop="transferOrgNo" width="150" />
      <el-table-column label="转入档案室编号" align="center" prop="transferInRoomNo" width="120"/>
      <el-table-column label="转出档案室编号" align="center" prop="transferOutRoomNo" width="120"/>
      <el-table-column label="盒数量" align="center" prop="boxNum" width="80" />
      <el-table-column label="袋数量" align="center" prop="bagNum" width="80"/>
      <el-table-column label="用户编号" align="center" prop="custNo" />
      <el-table-column label="档案编号" align="center" prop="archNo" />
      <el-table-column label="档案名称" align="center" prop="archName" />
      <el-table-column label="档案盒号" align="center" prop="boxNo" />
      <el-table-column label="库位号" align="center" prop="houseLocationNo" />
      <el-table-column label="转入后档案盒号" align="center" prop="inBoxNo" width="150" />
      <el-table-column label="转入后库位号" align="center" prop="inHouseLocationNo" width="120" />
      <el-table-column label="转存状态" align="center" prop="status" >
        <template #default="scope">
          <dict-tag :options="rollover_status" :value="scope.row.status"  width="100"/>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="totalDA>0&&DAShow"
      :total="totalDA"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
    <!--Box-->
    <el-table :data="ArchiveUploadTaskBoxList" @selection-change="handleSelectionChange" v-show="BoxShow" >
      <el-table-column label="转存任务编号" align="center" prop="transferNo" width="120"/>
      <el-table-column label="申请供电单位编号" align="center" prop="orgNo" width="150" />
      <el-table-column label="转入供电单位编号" align="center" prop="transferOrgNo" width="150" />
      <el-table-column label="转入档案室编号" align="center" prop="transferInRoomNo" width="120"/>
      <el-table-column label="转出档案室编号" align="center" prop="transferOutRoomNo" width="120"/>
      <el-table-column label="盒数量" align="center" prop="boxNum" width="80" />
      <el-table-column label="袋数量" align="center" prop="bagNum" width="80"/>
      <el-table-column label="用户编号" align="center" prop="custNo" width="150" />
      <el-table-column label="盒条码" align="center" prop="boxBarCode" width="150" />
      <el-table-column label="档案盒号" align="center" prop="boxNo" width="150" />
      <el-table-column label="库位号" align="center" prop="houseLocationNo"  width="150"/>
      <el-table-column label="转入后库位号" align="center" prop="inHouseLocationNo" width="150" />
    </el-table>
    <pagination
        v-show="totalBox>0&&BoxShow"
        :total="totalBox"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList1"
    />
    <!--Box-->
    <el-table :data="ArchiveUploadTaskBagList" @selection-change="handleSelectionChange" v-show="BagShow">
      <el-table-column label="转存任务编号" align="center" prop="transferNo" width="120"/>
      <el-table-column label="申请供电单位编号" align="center" prop="orgNo" width="150" />
      <el-table-column label="转入供电单位编号" align="center" prop="transferOrgNo" width="150" />
      <el-table-column label="转入档案室编号" align="center" prop="transferInRoomNo" width="120"/>
      <el-table-column label="转出档案室编号" align="center" prop="transferOutRoomNo" width="120"/>
      <el-table-column label="盒数量" align="center" prop="boxNum" width="80" />
      <el-table-column label="袋数量" align="center" prop="bagNum" width="80"/>
      <el-table-column label="用户编号" align="center" prop="custNo" />
      <el-table-column label="袋条码" align="center" prop="bagCode" />
      <el-table-column label="档案袋编号" align="center" prop="bagNo" width="110"/>
      <el-table-column label="档案盒号" align="center" prop="boxNo" />
      <el-table-column label="库位号" align="center" prop="houseLocationNo" />
      <el-table-column label="转入后档案盒号" align="center" prop="inBoxNo" width="150"/>
      <el-table-column label="转入后库位号" align="center" prop="inHouseLocationNo" width="150"/>
      <el-table-column label="转存状态" align="center" prop="status" >
        <template #default="scope">
          <dict-tag :options="rollover_status" :value="scope.row.status"  width="100"/>
        </template>
      </el-table-column>
    </el-table>
    <pagination
        v-show="totalBag>0&&BagShow"
        :total="totalBag"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList2"
    />
  </div>
</template>

<script setup name="ArchiveUploadTaskArchive">
import { listArchiveUploadTaskArchive, getArchiveUploadTaskArchive, delArchiveUploadTaskArchive, addArchiveUploadTaskArchive, updateArchiveUploadTaskArchive } from "@/api/archive/ArchiveUploadTaskArchive";
import {getCurrentInstance, reactive, ref, toRefs} from "vue";
import {listArchiveUploadTaskBag} from "@/api/archive/ArchiveUploadTaskBag";
import {listArchiveUploadTaskBox} from "@/api/archive/ArchiveUploadTaskBox";
const { proxy } = getCurrentInstance();

const ArchiveUploadTaskArchiveList = ref([]);
const ArchiveUploadTaskBoxList = ref([]);
const ArchiveUploadTaskBagList = ref([]);

const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const totalDA = ref(0);
const totalBox= ref(0);
const totalBag= ref(0);
const title = ref("");
let DAShow=ref(false);
let BagShow=ref(false);
let BoxShow=ref(false);
const {
  push_status,
  execut_result,
  rollover_status
} = proxy.useDict('push_status','execut_result','rollover_status');
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    roomNo: null,
    transferOrgNo: null,
    transferNo: null,
    transferOutRoomNo: null,
    transferinRoomNo: null,
    appReason: null,
    status: null,
  },
  rules: {
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询转存档案列表 */
function getList() {
  loading.value = true;
  listArchiveUploadTaskArchive(queryParams.value).then(response => {
    ArchiveUploadTaskArchiveList.value = response.rows;
    totalDA.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    taskId: null,
    custNo: null,
    archNo: null,
    archName: null,
    boxNo: null,
    houseLocationNo: null,
    inBoxNo: null,
    inHouseLocationNo: null
  };
  proxy.resetForm("ArchiveUploadTaskArchiveRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
  getList1();
  getList2();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加转存档案";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const id = row.id || ids.value
  getArchiveUploadTaskArchive(id).then(response => {
    form.value = response.data;
    open.value = true;
    title.value = "修改转存档案";
  });
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["ArchiveUploadTaskArchiveRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateArchiveUploadTaskArchive(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addArchiveUploadTaskArchive(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除转存档案编号为"' + ids + '"的数据项？').then(function() {
    return delArchiveUploadTaskArchive(ids);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('archive/ArchiveUploadTaskArchive/export', {
    ...queryParams.value
  }, `转存档案详情记录_${new Date().getTime()}.xlsx`)
}
/** 导出按钮操作 */
function handleExportBag() {
  proxy.download('archive/ArchiveUploadTaskBag/export', {
    ...queryParams.value
  }, `转存档案袋详情记录_${new Date().getTime()}.xlsx`)
}
/** 导出按钮操作 */
function handleExportBox() {
  proxy.download('archive/ArchiveUploadTaskBox/export', {
    ...queryParams.value
  }, `转存档案盒详情记录_${new Date().getTime()}.xlsx`)
}

function getList1() {
  loading.value = true;
  listArchiveUploadTaskBag(queryParams.value).then(response => {
    ArchiveUploadTaskBagList.value = response.rows;
    totalBag.value = response.total;
    loading.value = false;
  });
}
/** 查询转存档案盒列表 */
function getList2() {
  loading.value = true;
  listArchiveUploadTaskBox(queryParams.value).then(response => {
    ArchiveUploadTaskBoxList.value = response.rows;
    totalBox.value = response.total;
    loading.value = false;
  });
}

function DAVisible(){
   DAShow.value=true;
   BagShow.value=false;
   BoxShow.value=false;
   getList();
}
function BoxVisible(){
  DAShow.value=false;
  BagShow.value=false;
  BoxShow.value=true;
  getList2();
}
function BagVisible(){
  DAShow.value=false;
  BagShow.value=true;
  BoxShow.value=false;
  getList1();
}
DAVisible();
</script>
